package com.github.prontera.util;

import java.math.BigDecimal;

public class ScoreUtils {

	public static double computeScore(int s) {
		if (s >= 0) {
			return addScore(s);
		} else {
			return subScore(s);
		}
	}

	public static double addScore(int s) {
		int[] indexs = { 1, 100, 1000, 10000 };
		double[] rates = { 0.01, 0.001, 0.0001 };
		double[] scores = { 3, 4, 5 };
		double defaultScore = 2;
		for (int i = 0; i < indexs.length; i++) {
			if (s > indexs[i] && s <= indexs[i + 1]) {
				return (new BigDecimal(String.valueOf(scores[i] - 1))).add(new BigDecimal(String.valueOf(s * rates[i]))).doubleValue();
			}
		}
		return defaultScore;
	}

	public static double subScore(int s) {
		int[] indexs = { 1, 100, 1000, 10000 };
		double[] rates = { 0.005, 0.0005, 0.00005 };
		double[] scores = { 1.5, 0.5, 0 };
		double defaultScore = 2;
		for (int i = 0; i < indexs.length; i++) {
			if (s > indexs[i] && s <= indexs[i + 1]) {
				return (new BigDecimal(String.valueOf(scores[i] + 0.5))).subtract(new BigDecimal(String.valueOf(s * rates[i]))).doubleValue();
			}
		}
		return defaultScore;
	}

	public static void main(String[] args) {
		// System.out.println(computeScore(897));
		// int s = 90;
		// int [] indexs = {1,100,1000,10000};
		// double [] rates = {0.01,0.001,0.0001};
		// double [] scores = {3,4,5};
		// double sum = 2;
		// for (int i = 0; i < indexs.length; i++) {
		// if(s>indexs[i] && s<indexs[i+1]){
		// System.out.println(scores[i]-1+s*rates[i]);
		// }
		// }
		//
		//
		// if(s<=100){
		// sum += s*0.01;
		// }
		// if(s>100 && s<=1000){
		// sum += 100*0.01+(s-100)*0.001;
		// }
		// if(s>1000 & s<=10000){
		// sum += 100*0.01+(1000-100)*0.001+(s-1000)*0.0001;
		// }
		// System.out.println(sum);
		//
		// sum=2;
		// if(s>indexs[0] && s<=indexs[1]){
		// sum += s*rates[0];
		// }
		// if(s>indexs[1] && s<=indexs[2]){
		// sum += indexs[1]*rates[0]+(s-indexs[1])*rates[1];
		// }
		// if(s>indexs[2]){
		// sum +=
		// indexs[1]*rates[0]+(indexs[2]-indexs[1])*rates[1]+(s-indexs[2])*rates[2];
		// }
		//
		// System.out.println(sum);
	}
}
